<template>
	<view :class="{'my-tabs':true,'space-between':formatBe}">
		<view  v-for="(item,index) in getModelData" :key="index" :class="{'tab-item':true,'active':formatIndex==index}" @tap="tap(index,item)">
			{{item[labelKey]}}
		</view>
	</view>
</template>

<script>
	export default {
		props : {
			modelData: {
				type: Array,
				default: []
			},
			initIndex: {
				type: Number,
				default: 0
			},
			labelKey : {
				type: String,
				default: 'label',
			}
		},
		data() {
			return {
				
			}
		},
		computed:{
			getModelData(){
				return this.modelData
			},
			formatBe(){
				return this.modelData
						?this.modelData.length>4?true:false
						:false
			},
			formatIndex(){
				return this.initIndex
			}
		},
		methods: {
			tap(index,item){
				this.$emit("change",index,item);
			}
		}
	}
</script>
<style lang='scss'>
	.my-tabs {
		height: 88upx;
		font-size: 32upx;
		display: flex;
		justify-content: space-around;
		box-sizing: border-box;
		min-width: 100%;
		overflow-x: auto;
		
		.tab-item{
			line-height: 48upx;
			padding: 20upx 0;
			min-width: 50upx;
			text-align: center;
		}
		.tab-item.active{
			position: relative;
			color: black;
		}
		.tab-item.active::after{
			content: "";
			position: absolute;
			bottom: 0;
			left:50%;
			transform: translateX(-50%);
			width: 100%;
			border-bottom: 8upx solid black;
			animation: test ease 1 1.5s;
		}
	}
	.my-tabs.space-between{
		justify-content: space-between;
	}
	@keyframes test{
		0%{width: 100%}
		50%{width: 150%}
		100%{width: 100%}
	}
</style>
